-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Enable geom_ribbon() to draw separate lines for upper and lower intervals #3529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable geom_ribbon() to draw separate lines for upper and lower intervals #3529
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but @hadley should chime in on breaking changes
Thanks! I'm wondering how this breaking change should be described on NEWS. I'll wait for Hadley's comment. |
Can you explain how this would break existing code? I think the main change is that it won't draw vertical lines on either end, right? |
It's visually breaking, not something that makes any old code throw an error... I think we had a couple of those for the 3.2.0 release as well. But the NEWS will get rewritten come release so don't worry to much about it right now |
Yeah, I wouldn't call this a breaking change then. |
It just occurred to me that this is related to and will influence request for only drawing upper line in We should make sure that the correct line is drawn in geom_area if it dips or is fully below 0 |
Thanks, I got it.
Thanks, I'll consider this. But, I didn't think about the impact on |
Hmm... after some thinking, now I'm not sure if this is OK for devtools::load_all("~/Documents/repo/ggplot2")
#> Loading ggplot2
huron <- base::data.frame(year = 1875:1972, level = as.vector(LakeHuron))
h <- ggplot(huron, aes(year))
h + geom_area(aes(y = level), alpha = 0.5, colour = "black", size = 2) Created on 2019-10-08 by the reprex package (v0.3.0) We probably need these 3 types of Geoms here.
|
I think I don't think anyone wants area plots with upper and lower |
After some thinking, now I agree with you here. I think there are some options to implement this. For example:
I'll use the option 2 because it might be good to provide an option to fall back to the previous behavour (polygon). |
It seems I need to add some tweaks on devtools::load_all("~/Documents/repo/ggplot2/")
#> Loading ggplot2
d <- base::data.frame(x = 1:10, y = 5 - 1:10)
p1 <- ggplot(d, aes(x, ymin = 0, ymax = y)) +
geom_ribbon(alpha = 0.3, colour = "red", size = 3, outline.type = "upper")
p2 <- ggplot(d, aes(x, y)) +
geom_area(alpha = 0.3, colour = "red", size = 3, outline.type = "upper")
patchwork::wrap_plots(p1, p2) Created on 2019-10-16 by the reprex package (v0.3.0) |
Probably, I need another version of |
This is not the domain of positions IMO... Pretty sure the reason for what you are seeing is that |
I too thought so at first, but Lines 170 to 187 in 40e8b60
I think the call of Lines 220 to 221 in 40e8b60
|
damn, you are probably right... that is inconvenient Maybe position_stack should keep track of which values it flip and switch them back in the end |
I've created a PR that addresses the observed problems with geom_area I think we should have a switch for the new behaviour, both in geom_ribbon and geom_area... there will be some breaking visual changes and giving people a way to opt out will be good. I think the new behaviour should be default, though. Am I right in that the current implementation doesn't allow for old-style full stroking? |
@yutannihilation can you check that everything is as it should be after the merge of #3673? If so I think we can finish this off |
Co-Authored-By: Thomas Lin Pedersen <thomasp85@gmail.com>
Thanks, confirmed the problem is now fixed after #3673. devtools::load_all("~/Documents/repo/ggplot2/")
#> Loading ggplot2
d <- base::data.frame(x = 1:10, y = 5 - 1:10)
p1 <- ggplot(d, aes(x, ymin = 0, ymax = y)) +
geom_ribbon(alpha = 0.3, colour = "red", size = 3, outline.type = "upper")
p2 <- ggplot(d, aes(x, y)) +
geom_area(alpha = 0.3, colour = "red", size = 3, outline.type = "upper")
patchwork::wrap_plots(p1, p2) Created on 2019-12-18 by the reprex package (v0.3.0)
Sorry, I missed this comment. Yes, I agree with you and the users can specify Lines 25 to 27 in 7c6d3d5
|
I'm merging this. Thanks for reviewing multiple times! |
Fix #3503
This PR changes
GeomRibbon
from a normal polygon to a polygon + two lines; whileGeomRibbon
is implemented as a polygon, considering that the nature of this geom is to indicate the upper and the lower range along X axis, I believe it's natural thatGeomRibbon
comes with two lines.Though this is a breaking change, I expect there's very few users using
GeomRibbon
as a closed line. But, I'm not fully confident... If this expectation would fail, I'll withdraw this PR and create a new geom.Created on 2019-09-02 by the reprex package (v0.3.0)